package com.jiamao.goplay.ui.user.vm;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;

import com.jiamao.goplay.bean.InviteMeListItme;
import com.jiamao.goplay.ui.discover.SearchFragment;
import com.jiamao.goplay.ui.discover.vm.AddrDetailVM;
import com.jiamao.goplay.ui.user.OthersUserInfoFragment;
import com.netease.nim.uikit.api.NimUIKit;

import androidx.databinding.ObservableField;
import androidx.databinding.ObservableInt;
import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.base.MultiItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;

public class UserInvitationItemVM extends MultiItemViewModel {


    public ObservableField<String> imgUrl = new ObservableField<>("");
    public ObservableField<String> name = new ObservableField<>("");
    public ObservableField<String> statusDes = new ObservableField<>("");
    public ObservableField<String> userDes = new ObservableField<>("");

    public ObservableInt ypdBtnVisibility = new ObservableInt(View.GONE);
    public ObservableInt yqBtnVisibility = new ObservableInt(View.GONE);
    public ObservableInt jsyqBtnVisibility = new ObservableInt(View.GONE);

    public ObservableInt jcpdBtnVisibility = new ObservableInt(View.GONE);
    public ObservableInt scyqBtnVisibility = new ObservableInt(View.GONE);

    public ObservableField<Integer> isVip = new ObservableField<>();
    public ObservableField<Integer> isShming = new ObservableField<>();
    public ObservableField<Integer> isRenXiang = new ObservableField<>();

    private String id,uid;

    public UserInvitationItemVM(@NonNull BaseViewModel viewModel, InviteMeListItme inviteMeListItme) {
        super(viewModel);

        if (inviteMeListItme==null){
            return;
        }
        uid = inviteMeListItme.getUid();
        id = inviteMeListItme.getId();
        imgUrl.set(inviteMeListItme.getAvatar());
        name.set(inviteMeListItme.getNickname());

        String sex = inviteMeListItme.getGender() == 1 ?"他":"她";
        String userDesStr =  sex+"邀请我去："+inviteMeListItme.getPlaceName();
        userDes.set(userDesStr);



        statusDes.set(""+inviteMeListItme.getTimeStr());
        switch (inviteMeListItme.getStatus()){
            case 0:
                jsyqBtnVisibility.set(View.VISIBLE);
                break;
            case 1:
                jsyqBtnVisibility.set(View.VISIBLE);
                scyqBtnVisibility.set(View.VISIBLE);
                ypdBtnVisibility.set(View.GONE);
                break;
            case 2:
                ypdBtnVisibility.set(View.VISIBLE);
                scyqBtnVisibility.set(View.GONE);
                jcpdBtnVisibility.set(View.VISIBLE);
                break;
            case 3:
              //  yyqBtnVisibility.set(View.VISIBLE);
                break;

        }

       // scyqBtnVisibility.set(View.VISIBLE);


        isVip.set( View.GONE);
        isRenXiang.set(inviteMeListItme.getAvatarVerified() == 0 ? View.GONE : View.VISIBLE);
        isShming.set(inviteMeListItme.getRealNameVerified() == 0 ? View.GONE : View.VISIBLE);

    }

    //条目的点击事件
    public BindingCommand itemClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {

         //   viewModel.startContainerActivity(SearchFragment.class.getCanonicalName());
        }
    });

    //条目的点击事件
    public BindingCommand jsyqClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {

            ((UserInvitationVM)viewModel).jieshouyaoqing(id,UserInvitationItemVM.this);
        }
    });


    //条目的点击事件
    public BindingCommand ypdClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {

            ((UserInvitationVM)viewModel).startChat(uid);
        //    NimUIKit.startP2PSession(viewModel.getApplication(), uid);
            //((AddrDetailVM)viewModel).yaoqing(uid);
            // viewModel.startContainerActivity(SearchFragment.class.getCanonicalName());
        }
    });

    //条目的点击事件
    public BindingCommand jiechuClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {

            ((UserInvitationVM)viewModel).jiechupd(uid,UserInvitationItemVM.this);
         //   NimUIKit.startP2PSession(viewModel.getApplication(), uid);
            //((AddrDetailVM)viewModel).yaoqing(uid);
            // viewModel.startContainerActivity(SearchFragment.class.getCanonicalName());
        }
    });


    //条目的点击事件
    public BindingCommand delyqClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {

          //  ((UserInvitationVM)viewModel).(id,UserInvitationItemVM.this);
            ((UserInvitationVM)viewModel).jiechuyaoqing(id,UserInvitationItemVM.this);
           // NimUIKit.startP2PSession(viewModel.getApplication(), uid);
            //((AddrDetailVM)viewModel).yaoqing(uid);
            // viewModel.startContainerActivity(SearchFragment.class.getCanonicalName());
        }
    });

    //条目的点击事件
    public BindingCommand imgClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {

            Bundle bd = new Bundle();
            bd.putString("uid",uid);
            viewModel.startContainerActivity(OthersUserInfoFragment.class.getCanonicalName(),bd);
            //  viewModel.startContainerActivity(SearchFragment.class.getCanonicalName());
        }
    });



    public void updateypd(){
        jsyqBtnVisibility.set(View.GONE);
        ypdBtnVisibility.set(View.VISIBLE);
        statusDes.set("配对于 刚刚");

        jcpdBtnVisibility.set(View.VISIBLE);
        scyqBtnVisibility.set(View.GONE);



    }



}
